#coding=utf-8
import re
from urllib.parse import urlencode
import requests

class ContentConfig:
    def __init__(self):
        self.bokeeName = 'tefenxiang',
        self.username = '2676551360@qq.com',
        self.password = '1987wade',
        self.title = '',
        self.content ='',
        self.columnName = '',   #分类名字1
        self.addType ='',       #分类2
        self.tags ='',          #标签
        self.brief = ''         #内容摘要

def bokeePOST(Config):
    try:
        loginUrl = 'http://tefenxiang.blog.bokee.net/usermodule/userManager_quickLogin.do'
        formdata1 = {
            'username': '2676551360@qq.com',
            'password': '1987wade'
        }
        session = requests.session()
        html1 = session.post(loginUrl, formdata1, timeout=10)  # 登录
        print(f'登录状态: {html1.status_code}')
        postContentUrl = 'http://tefenxiang.blog.bokee.net/bloggermodule/blogadmin2_saveblog.do'
        formdata2 = {
            'bokeeName': 'tefenxiang',
            'id': '',
            'action': 'saveEntry',
            'title': Config.title,
            'content': Config.content,
            'columnName': Config.columnName,
            'addType': Config.addType,
            'tags': Config.tags,
            'brief': Config.brief,
            'visibility': '100',  # 公开方式，保持默认
            'commentable': '1',  # 开启评论，保持默认
            'displayControl': '2',  # 摘要模式，保持默认
            'stateNo': '1'  # 状态码，保持默认
        }
        html2 = session.post(postContentUrl, formdata2, timeout=10)

        restr = re.compile('<input type="hidden" name="id" value="(\d+)">')
        contentid = restr.findall(html2.text)
        print(contentid)

        # 投稿
        url3 = 'http://tefenxiang.blog.bokee.net/bloggermodule/blogadmin2_saverelations.do'
        formdata3 = {
            'dailyId': '14',
            'dailyColumnsId': '78',
            'companyId': '-999',
            'typeId': '-999',
            'circleId': '-999',
            'id': contentid,
            'buildingId': '-999',
        }
        session.post(url3, formdata3, timeout=10)  # 投稿
        print('发布成功')
    except:
        print('发布错误')



if __name__ == '__main__':
    # 调用企业博客发帖模块函数块需要的内容----START
    bokeeconfig =ContentConfig()
    bokeeconfig.title = '【图文体验】峰米Smart评价怎么样？？觉得峰米投影仪好不好',
    bokeeconfig.content = '',
    bokeeconfig.columnName = '值得买',  # 分类名字1
    bokeeconfig.addType = '值得买',  # 分类2
    bokeeconfig.tags = '峰米Smart真不错',  # 标签
    bokeeconfig.brief = '峰米Smart真不错'  # 内容摘要
    bokeePOST(bokeeconfig)
    # print(bokeeconfig.__dict__)
    # 调用企业博客发帖模块函数块需要的内容----END


